
function save() {
    function onErrorReadFile(error) {
    }

    function successFun(fileEntry) {
        fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function() {
                console.log("Successful file write: " + this.result);
                var base64Data = this.result;
                cordova.base64ToGallery(
                    base64Data,
                    {
                        prefix: 'img_',
                        mediaScanner: true
                    },

                    function(path) {
                        alert("保存成功");
                    },

                    function(err) {

                    }
                );
            };
            reader.readAsDataURL(file);
        }, onErrorReadFile);
    }

    function failFun(error) {
        console.log("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
        alert('图片下载失败。');
    }

    function progressFun(progressEvent) {
        var progress = progressEvent.loaded / progressEvent.total * 100;
        document.getElementById("progress1").innerHTML = "下载："+progress+"%100";
    }

    var uri = "https://cordova.apache.org/static/img/cordova_bot.png";
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        var targetPath = dirEntry.toURL() + "corplogo.png";
        var fileTransfer = new FileTransfer();
        fileTransfer.onprogress = progressFun;
        fileTransfer.download(
            uri,
            targetPath,
            successFun,
            failFun,
            false,
            {}
        );
    });
}

function save2() {

    function onErrorReadFile(error) {
    }
    function successFun(fileEntry) {
        fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function() {
                console.log("Successful file write: " + this.result);
                var base64Data = this.result;
                window.imageSaver.saveBase64Image(
                    {
                        data:base64Data,
                        prefix: 'img_',
                        format: 'JPG',
                        quality: 80,
                        mediaScanner: true
                    },

                    function(path) {
                        alert("保存成功");
                    },

                    function(err) {

                    }
                );
            };
            reader.readAsDataURL(file);
        }, onErrorReadFile);
    }

    function failFun(error) {
        console.log("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " + error.target);
        alert('图片下载失败。');
    }

    function progressFun(progressEvent) {
        var progress = progressEvent.loaded / progressEvent.total * 100;
        document.getElementById("progress2").innerHTML = "下载："+progress+"%100";
    }

    var uri = "https://cordova.apache.org/static/img/cordova_bot.png";
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        var targetPath = dirEntry.toURL() + "corplogo.png";
        var fileTransfer = new FileTransfer();
        fileTransfer.onprogress = progressFun;
        fileTransfer.download(
            uri,
            targetPath,
            successFun,
            failFun,
            false,
            {}
        );
    });
}

function deleteFile() {
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
        var targetPath = dirEntry.toURL() + "corplogo.png";
        alert(targetPath);
        var params = {data: targetPath};
        window.imageSaver.removeImage(params,
            function (filePath) {
                alert('File removed from ' + filePath);
            },
            function (msg) {
                alert(msg);
            }
        );
    });

}
